// userPackage/pages/balanceList/balanceList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showNum: 5,
    isShow: false,
    userBalance: 0, //账户余额
    list: [],
    showRuleBox: false
  },


  rulesHandle() {
    this.setData({
      showRuleBox: !this.data.showRuleBox
    })
  },


  showAllHandle() {
    var isShow = this.data.isShow,
      showNum = this.data.showNum,
      list = this.data.list;

    isShow = !isShow
    showNum = isShow ? list.length : 5
    this.setData({
      isShow,
      showNum
    })

  },


  toPage(e) {
    var obj = e.currentTarget.dataset.obj;
    console.log(obj);
    if (obj.orderNum == 0) {
      return
    }
    this.getDetail(obj.orderNum)
  },

  getDetail(orderNum) {
    var url = app.globalData.url + "ScOrder/listOrderByNumber";
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {
        orderNum,
      }, res => {
        console.log(res);
        if (res.flag) {
          var datas = res.data;
          console.log(datas);
          wx.hideLoading()
          wx.navigateTo({
            url: '/userPackage/pages/orderDetail/orderDetail?order=' + JSON.stringify(datas),
          })

        }
      },
      err => {
        console.log(err);
      })

  },

  tiHandle() {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '提现' + that.data.userBalance + '元',
      complete: (res) => {
        if (res.cancel) {

        }
        if (res.confirm) {

        }
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.setData({
      list: JSON.parse(options.list)
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      userBalance: app.globalData.userBalance
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})